package com.spring.storagemanagement_03.controller;


import com.spring.storagemanagement_03.mapper.UserMapper;
import com.spring.storagemanagement_03.pojo.dto.UserDto;
import com.spring.storagemanagement_03.pojo.vo.UserVo;
import com.spring.storagemanagement_03.response.ResultVO;
import com.spring.storagemanagement_03.response.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/v1/users/")
public class UserController {
    @Autowired
    UserMapper userMapper;

    @PostMapping("login")
    public ResultVO login(@RequestBody UserDto userDto){
        System.out.println("userDto = " + userDto);
        UserVo userVo = userMapper.selectByName(userDto.getUserName());
        System.out.println(userVo);
        if(userVo ==null){
            return new ResultVO(StatusCode.USERNAME_ERROR);
        }
        if(userVo.getPassword().equals(userDto.getPassword())){
            return ResultVO.ok(1);
        }
        return new ResultVO(StatusCode.OPERATION_FAILED);
    }
    @RequestMapping("")
    public ResultVO userIndexInfo(){
        List<UserVo>list=userMapper.selectUserInfo(1);//暂时没做安全块，
        System.out.println(list);
        return ResultVO.ok(list);
    }

}
